package ylyhappy.cn.ideavim.ui.myhandler;

import android.os.Handler;
import android.os.Looper;

import androidx.annotation.NonNull;


public class MyHandler extends Handler {

    ProgressBarAction progressBarAction = null;

    public void registryProgressbarHandler(ProgressBarAction progressBarAction) {
        this.progressBarAction = progressBarAction;
    }

    public MyHandler(Looper looper) {
        super(looper);
    }

    public enum MESSAGE_TYPE {
        PROGRESSBAR_LOADING, // 进度条正在加载
        PROGRESSBAR_LOADED,  // 进度条加载完毕
    }


    /**
     * 我想把 msg的what字段换成枚举，但是Message这个类是final的我不呢个继承。
     *
     */
    public void handleMessage(@NonNull MyMessage msg) {
        switch (msg.getMsgWhat()) {
            case PROGRESSBAR_LOADING: {
                if (this.progressBarAction != null) { this.progressBarAction.onProgressBarLoading(); }
                break;
            }
            case PROGRESSBAR_LOADED: {
                if (this.progressBarAction != null) { this.progressBarAction.onProgressBarLoaded(); }
                break;
            }
        }


//        super.handleMessage(msg.msg);
    }

    public void sendMessage(@NonNull MyMessage msg) {
        handleMessage(msg);
        super.sendMessage(msg.msg);
    }

}
